package helixoide;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Config 
{
	private String passwordConnect;
	private String passwordReceive;
	private String serverURL;
	private String ourURL;
	private String ourName;
	private String Secret;
	private int listenPort;
	private String logFile;
	public Config(String file)
	{
		File theConfigFile = new File(file);
		Scanner fileScan = null;
		try
		{
	
			fileScan = new Scanner(theConfigFile);
		}
		catch(FileNotFoundException e)
		{
			e.printStackTrace();
			System.out.println("Initialisation failed: Config Error: File Not Found");
			System.exit(1);
		}
		String theFile = "";
		String in = "";
		String[] temp = null; 
		while(fileScan.hasNextLine())
		{
			in = fileScan.nextLine();
			if(in.startsWith("//"))
			{
				//System.out.println("Skipping: " + in);
				continue;
			}
			else
			{
				
				//System.out.println("adding: " + in);
				theFile += in + " ";
			}
		}
		Scanner configScan = new Scanner(theFile);//scan the string word by word in order to parse the config
		in = "";
		while(configScan.hasNext())
		{
			in = configScan.next();
			if(in.equalsIgnoreCase("irc-server"))
			{
				this.serverURL = configScan.next();
			}
			if(in.equalsIgnoreCase("password-connect"))
			{
				this.passwordConnect = configScan.next();
			}
			if(in.equalsIgnoreCase("LogFile"))
			{
				this.logFile = configScan.next();
			}
			if(in.equalsIgnoreCase("password-receive"))
			{
				this.passwordReceive = configScan.next();
			}
			if(in.equalsIgnoreCase("OurName"))
			{
				this.ourName = configScan.next();
			}
			if(in.equalsIgnoreCase("OurURL"))
			{
				this.ourURL = configScan.next();
			}
			if(in.equalsIgnoreCase("secret"))
			{
				this.Secret = configScan.next();
			}
			if(in.equalsIgnoreCase("listenport"))
			{
				this.listenPort = Integer.parseInt(configScan.next());
			}
		}
	}
	public int getPort()
	{
		return this.listenPort;
	}
	public String getLogFileName()
	{
		return this.logFile;
	}
	public String getOurName()
	{
		return this.ourName;
	}
	public String getOurURL()
	{
		return this.ourURL;
	}
	public String getServerURL()
	{
		return this.serverURL;
	}
	public String getPasswordConnect()
	{
		return this.passwordConnect;
	}
	public String getPasswordReceive()
	{
		return this.passwordReceive;
	}
	
}
